<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Go wasm</title>
</head>

<body>
    <script src="wasm_exec.js"></script>
    <script>
        if (!WebAssembly.instantiateStreaming) {
            // polyfill
            WebAssembly.instantiateStreaming = async (resp, importObject) => {
                const source = await (await resp).arrayBuffer()
                return await WebAssembly.instantiate(source, importObject)
            }
        }

        // Promise to load the wasm file
        function loadWasm(path) {
            const go = new Go() 
            return new Promise((resolve, reject) => {
                WebAssembly.instantiateStreaming(fetch(path), go.importObject)
                    .then(result => {
                        go.run(result.instance)
                        resolve(result.instance)
                    })
                    .catch(error => {
                        alert(error);
                        reject(error)
                    })
            })
        }

        // Load the wasm file
        loadWasm("lib.wasm").then(wasm => {
            console.log("main.wasm is loaded ")
        }).catch(error => {
            console.error(error)
        })
    </script>
    <canvas id='canvas' width="1000" height="700" style="position: fixed; left: 0px; top: 0px;"></canvas>
</body>
</html>